home *** CD-ROM | disk | FTP | other *** search
/ Experimental BBS Explossion 3 / Experimental BBS Explossion III.iso / c / csetup.zip / CSETUP.C < prev    next >
C/C++ Source or Header  |  1993-12-23  |  5KB  |  238 lines

  1. /*
  2.     csetup.c
  3.  
  4.     Setup Program Written in the Mans language
  5.  
  6.     Another fine Herman Rodent production
  7.  
  8. */
  9.  
  10. // COPYRIGHT:
  11. //
  12. //   (C) Copyright Microsoft Corp. 1993.  All rights reserved.
  13. //
  14. //   You have a royalty-free right to use, modify, reproduce and
  15. //   distribute the Sample Files (and/or any modified version) in
  16. //   any way you find useful, provided that you agree that
  17. //   Microsoft has no warranty obligations or liability for any
  18. //   Sample Application Files which are modified.
  19. //
  20.  
  21. #include "csetup.h"
  22. #include "setupapi.h"
  23. #include <stdlib.h>
  24.  
  25.  
  26. //
  27. // global data specific to the app you are installing
  28. //
  29.  
  30. char *szAppName         = "CSetup";         // App name
  31. char *szCaption         = "'C' Setup";      // Caption
  32. char szDest[_MAX_PATH]  = "C:\\BOGUS";      // Destination path
  33. char *szProgmanGroup    = "C Setup";        // Progman group caption
  34.  
  35. //
  36. // general stuff
  37. //
  38.  
  39. HWND hwndFrame;                     // handle to setup frame window (hSetup)
  40. CATCHBUF CatchBuf;
  41. int Err;
  42.  
  43. //
  44. // local functions
  45. //
  46.  
  47. void Install(void);
  48.  
  49. //
  50. // Entry point
  51. //
  52.  
  53. int PASCAL WinMain(HINSTANCE hInstance,
  54.                    HINSTANCE hPrevInstance,
  55.                    LPSTR lpszCmdLine,
  56.                    int cmdShow)
  57. {
  58.     UINT ui;
  59.     char szInf[_MAX_PATH];
  60.  
  61.     //
  62.     // We don't allow multiple instances
  63.     //
  64.  
  65.     if (hPrevInstance) {
  66.         return 1;
  67.     }
  68.  
  69.     //
  70.     // Do any initial stuff
  71.     //
  72.  
  73.     dprintf("Initializing");
  74.     if (!InitSetup(lpszCmdLine)) {
  75.         Error("No main window");
  76.         return 1;
  77.     }
  78.  
  79.     hwndFrame = HwndFrame();
  80.  
  81.     //
  82.     // Setup a catch buffer so we can do something like
  83.     // ON ERROR GOTO
  84.     //
  85.  
  86.     if ((Err = Catch((int FAR *) CatchBuf)) != 0) {
  87.         goto Quit;
  88.     }
  89.  
  90.     //
  91.     // Set the background image and caption
  92.     //
  93.  
  94.     SetBitmap(szCUIDLL, LOGO);
  95.     SetWindowText(hwndFrame, szCaption);
  96.  
  97.     GetSymbolValue("STF_SRCINFPATH", szInf, sizeof(szInf));
  98.     if (!lstrlen(szInf)) {
  99.         GetSymbolValue("STF_CWDDIR", szInf, sizeof(szInf));
  100.         lstrcat(szInf, "CSETUP.INF");
  101.     }
  102.     dprintf("Reading ini file: %s", (LPSTR)szInf);
  103.     ReadInfFile(szInf);
  104.  
  105. Welcome:
  106.  
  107.     switch(UIStartDlg(szCUIDLL, WELCOME, "FInfoDlgProc", 
  108.         APPHELP, "FHelpDlgProc")) {
  109.     case CONTINUE:
  110.         UIPop(1);
  111.         break;
  112.  
  113.     default:
  114.         AskQuit();
  115.         goto Welcome;
  116.     }
  117.  
  118.  
  119. GetPath:
  120.     SetSymbolValue("EditTextIn", szDest);
  121.     SetSymbolValue("EditFocus", "END");
  122. GetPathL1:
  123.     ui = UIStartDlg(szCUIDLL, DESTPATH, 
  124.             "FEditDlgProc", APPHELP, "FHelpDlgProc");
  125.     GetSymbolValue("EditTextOut", szDest, sizeof(szDest));
  126.  
  127.     if (ui == CONTINUE) {
  128.         if (IsDirWritable(szDest) == 0) {
  129.             BadPath();
  130.             goto GetPathL1;
  131.         }
  132.         UIPop(1);
  133.     } else if (ui == REACTIVATE) {
  134.         goto GetPathL1;
  135.     } else if ( ui == BACK) {
  136.         UIPop(1);
  137.         goto Welcome;
  138.     } else {
  139.         AskQuit();
  140.         goto GetPath;
  141.     }
  142.  
  143.  
  144.     Install();
  145.  
  146.  
  147.     //
  148.     // Get here either by normal exit or from a Throw caused
  149.     // by some error handler
  150.     //
  151.  
  152. Quit:
  153.  
  154.     if (Err == 0) {
  155.         ui = EXITSUCCESS;
  156.      } else if (Err == STFQUIT) {
  157.         ui = EXITQUIT;
  158.     } else {
  159.         ui = EXITFAILURE;
  160.     }
  161.  
  162. QuitL1:
  163.     ui = UIStartDlg(szCUIDLL, ui, "FInfo0DlgProc", 0, "");
  164.     if (ui == REACTIVATE) {
  165.         goto QuitL1;
  166.     }
  167.     UIPop(1);
  168.     TerminateFrame();
  169.     return 0;
  170. }
  171.     
  172. // **********************************************
  173. // YOU CODE GOES HERE
  174. // **********************************************
  175.  
  176. void Install()
  177. {
  178.     char szSrcDir[_MAX_PATH];
  179.     char szTemp[_MAX_PATH];
  180.     char szIni[_MAX_PATH];
  181.     char buf[_MAX_PATH+256];
  182.  
  183.     GetSymbolValue("STF_SRCDIR", szSrcDir, sizeof(szSrcDir));
  184.  
  185.     //
  186.     // Create the destination directory
  187.     //
  188.  
  189.     CreateDir(szDest, cmoNone);
  190.  
  191.     //
  192.     // Open a log file and write some info to it
  193.     //
  194.  
  195.     MakePath(szDest, "LOGFILE.OUT", szTemp);
  196.     OpenLogFile(szTemp, 0);
  197.     WriteToLogFile("");
  198.     WriteToLogFile("  User chose as destination directory: %s", (LPSTR)szDest);
  199.     WriteToLogFile("");
  200.  
  201.     //
  202.     // Copy all the files 
  203.     //
  204.  
  205.     AddSectionFilesToCopyList("Files", szSrcDir, szDest);
  206.     CopyFilesInCopyList();
  207.  
  208.     //
  209.     // Modify INI files
  210.     //
  211.  
  212.     MakePath(szDest, "DEMO.INI", szIni);
  213.     CreateIniKeyValue(szIni, "Section 1", "Key 1", "Value 1" , cmoNone);
  214.     CreateIniKeyValue(szIni, "Section 2", "Key 2", "Value 2" , cmoNone);
  215.     CreateIniKeyValue(szIni, "Section 3", "Key 3", "Value 3" , cmoNone);
  216.   
  217.     //
  218.     // Create Progman groups and add items
  219.     //
  220.  
  221.     CreateProgmanGroup(szProgmanGroup, "", cmoNone);
  222.     ShowProgmanGroup(szProgmanGroup, 1, cmoNone);
  223.  
  224.     MakePath(szDest, "file1.txt", szTemp);
  225.     wsprintf(buf, "notepad.exe %s", (LPSTR)szTemp);
  226.     CreateProgmanItem(szProgmanGroup, "File 1", buf, "", cmoOverwrite);
  227.  
  228.     MakePath(szDest, "file2.txt", szTemp);
  229.     wsprintf(buf, "notepad.exe %s", (LPSTR)szTemp);
  230.     CreateProgmanItem(szProgmanGroup, "File 2", buf, "", cmoOverwrite);
  231.  
  232.     //
  233.     // close the log file
  234.     //
  235.  
  236.     CloseLogFile();
  237. }
  238.